/*
 *
 *  * AUTHOR：SIGHT
 *  *
 *  * DESCRIPTION：create the File, and add the content.
 *  *
 *  * Copyright © ZhiMore. All Rights Reserved
 *  *
 *
 */

package com.lx.commonlib.utils.ui;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;


import java.lang.reflect.Method;

import static android.content.Context.WINDOW_SERVICE;


public class UIUtils {

    /**
    * 方法说明:  sp转px
    * created by liuxiong on 2020/1/13 14:42
    */
    public static int sp2px(Context context, float spValue) {
        final float fontScale = context.getResources().getDisplayMetrics().scaledDensity;
        return (int) (spValue * fontScale + 0.5f);
    }

    /**
     * 将dip或dp值转换为px值，保证尺寸大小不变
     *
     * @param dipValue
     * @param context  （DisplayMetrics类中属性density）
     * @return
     */
    public static int dip2px(Context context, float dipValue) {
        final float scale = context.getResources().getDisplayMetrics().density;
        return (int) (dipValue * scale + 0.5f);
    }

    /**
    * 方法说明:  获取屏幕宽度
    * created by liuxiong on 2020/1/13 14:43
    */
    public static int getScreenWidth(Context context) {
        DisplayMetrics metric = new DisplayMetrics();
        WindowManager wm = (WindowManager) context.getSystemService(WINDOW_SERVICE);
        wm.getDefaultDisplay().getMetrics(metric);
        return metric.widthPixels;
    }

    /**
     * 方法说明:  获取屏幕高度
     * created by liuxiong on 2020/1/13 14:43
     */
    public static int getScreenHeight(Context context) {
        DisplayMetrics metric = new DisplayMetrics();
        WindowManager wm = (WindowManager) context.getSystemService(WINDOW_SERVICE);
        wm.getDefaultDisplay().getMetrics(metric);
        return metric.heightPixels;
    }
}
